clear
clear all
cap log close

log using "log-files/3_Table_F1.smcl", replace smcl

timer on 2

* Loading myround, which is a program written by us to round numbers
cap program drop myround
include "codes/auxiliary_programs/myround.ado"

*-----------*
* Table F.1 *
*-----------*
	use "data/outputs/RD_sortings.dta", clear

	foreach x of varlist R01-R22 {
		quietly sum `x', detail
		local mean_`x' = r(mean)
		local median_`x' = r(p50)
	}

	count
	local num_sims = r(N)

	clear
	set obs 3

	foreach k of numlist 1 3 {
		local kk = `k' - 1

		cap gen pval_mean = .
		replace pval_mean = `mean_R`kk'2' if _n == `k'

		cap gen pval_median = .
		replace pval_median = `median_R`kk'2' if _n == `k'

		cap gen estim_mean = .
		replace estim_mean = `mean_R`kk'1' if _n == `k'

		cap gen estim_median = .
		replace estim_median = `median_R`kk'1' if _n == `k'
	}

	drop if _n == 2

	foreach x of varlist pval* estim* {
		myround `x', decimals(3)
	}

	preserve
		use "data/outputs/computo_verificadortrepdate_nomissings.dta", clear

		sum pcs_so if trep_date_verificador >= tc(20oct2019 19:40:57)
		local cutoff = r(min)
	restore

	gen N_sims = "`num_sims'"
	gen cutoff = "`cutoff'" if _n == 1
	replace cutoff = "0.950" if _n ==2
	destring cutoff, replace
	myround cutoff, decimals(3)

	gen date = "10/20/2019 19:40:57" if _n == 1
	replace date = "10/20/2019 20:03:59" if _n == 2

	replace N_sims="1,000" if N_sims=="1000"

	gen t=_n*(-1)
	sort t
	drop t

	egen c = concat(cutoff date pval_mean pval_median ///
		estim_mean estim_median N_sims), punct(" & ")
	keep c
	replace c = c + " \\"

	outsheet using "outputs/generated/Table_F1.tex", replace nonames ///
		noquote nolabel

*------------------------------------------------------------------------------*
timer off 2
timer list 2

log close
clear all
